//
//  YSpreadViewItemViewSubViewItemView.m
//  yuimall_Iphone
//
//  Created by yuike6 yuike6 on 12-4-18.
//  Copyright (c) 2012年 yuike. All rights reserved.
//

#import "YSpreadViewItemViewSubViewItemView.h"
#import "header.h"

@interface YSpreadViewItemViewSubViewItemView (private)
- (void) fillData2Views;
- (void) privateInit;
@end

@implementation YSpreadViewItemViewSubViewItemView

@synthesize contentView = contentView_;
@synthesize data = data_;
@synthesize delegate = delegate_;

-(void) dealloc
{   
    
    YRelease(contentView_);
    YRelease(data_)    
    YRelease(title_)
    
    [super dealloc];
}

-(void) setData:(YSpreadViewItemModel *)dataValue
{
    YRelease(data_)
    data_ = [dataValue retain];
    
    [self fillData2Views];
}

-(id) init{
    self = [super init];
    if (self) {
        [self privateInit];
    }
    return self;
}


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
         [self privateInit];
    }
    return self;
}

-(void) privateInit
{
    if (self.bInited) 
    {
        return;
    }
        
    UIViewEx * tmp_contentView = [[UIViewEx alloc] init];
    [tmp_contentView setBackgroundColor:RGB(240, 240, 240)];
    self.contentView = tmp_contentView;
    YRelease(tmp_contentView);
    [self addSubview:self.contentView];
    
    [self setBackgroundColor:RGB(230, 230, 230)];
    self->title_ = [[UILabel alloc] init];    
    [self->title_ setTextAlignment:UITextAlignmentCenter];
    [self->title_ setFont:[UIFont systemFontOfSize:18]];
    
    [self.contentView addSubview:self->title_];    
    
    [self reAdjustLayout];
    self.bInited = TRUE;
}

- (void) fillData2Views
{
    [self->title_ setText:self.data.title];
}

-(void) setFrame:(CGRect)frame
{
    [super setFrame:frame];    
    [self reAdjustLayout];
}

-(void) reAdjustLayout
{
    [self.contentView setFrame:self.bounds];
    
    [self->title_ setFrame:CGRectMake(0, 1, self.width, self.height - 2)];
}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    [self.layer setBackgroundColor:COLOR_BLACK.CGColor];
//    [self setAlpha:0.4f];
    [self setNeedsDisplay];
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];
    [self.layer setBackgroundColor:COLOR_WHITE.CGColor];
    [self setAlpha:1.0f];
    [self setNeedsDisplay];
    DELEGATE_CALLBACK(clickSubItem:, self);
}


@end
